package com.opensdk.service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.opensdk.Parameter;
import com.opensdk.auth.AccessToken;
import com.opensdk.auth.Signature;
import com.opensdk.exception.OpenSNSException;

public class SohuBaseService extends AbstractService {
	
	private String appKey;
	
	private String appSecret;
	
	private AccessToken accessToken;
	
	private Signature signature;
	
	private List<Parameter> baseParameter = new ArrayList<Parameter>();

	public void setSignature(Signature signature) {
		this.signature = signature;
	}
	
	public SohuBaseService(String appKey, String appSecret,
			AccessToken accessToken) {
		this.appKey = appKey;
		this.appSecret = appSecret;
		this.accessToken = accessToken;
	}

	@Override
	protected List<Parameter> prepareParams(String method, String uri,
			List<Parameter> params, String format) {
//		if(accessToken == null){
//    		throw new IllegalArgumentException("accseeToken must not be null.");
//    	}
//		
//		params.addAll(baseParameter);
//		
//        return params;
		return null;
	}

	public void setBaseParameter(List<Parameter> baseParameter) {
		this.baseParameter = baseParameter;
	}
	
	public int call(String uri,List<Parameter> params) throws OpenSNSException{

		params.addAll(baseParameter);
		String oauth_signature = signature.getSignature("POST", uri, params, appSecret, accessToken.getTokenSecret());
		params.add(new Parameter("oauth_signature", oauth_signature));
		
		String result = super.getResult(uri, "POST", params, "json");
		
		return 1;
	}
	
	public int call(String uri,List<Parameter> params,File file) throws OpenSNSException{

		params.addAll(baseParameter);
		String oauth_signature = signature.getSignature("POST", uri, params, appSecret, accessToken.getTokenSecret());
		params.add(new Parameter("oauth_signature", oauth_signature));
		
		String result = super.getResult(uri, "POST", params,file, "json");
		
		return 1;
	}

}
